﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model.Miembro;
using System.Drawing;
using Model.Cuotas;
using System.Web.Security;

namespace Interfaces.Cuotas
{
    public partial class Ver : System.Web.UI.Page
    {
        PagoDeCuota mensual = null;
        PagoDeCuota anual = null;
        Int64 anioDeLaBase;
        Int64 mesDeLaBase;

        ClaseMiembro asdf = null;

        string res;

        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!User.Identity.IsAuthenticated)
                FormsAuthentication.RedirectToLoginPage();
            if ((Request.QueryString["va1"] != null))
            {
                try
                {
                    for (int i = 0; i < 12; i++)
                    {
                        PintarRojo(i + 1);
                    }
                    MultiView1.ActiveViewIndex = 0;
                    Int64 carnet = Convert.ToInt64(Request.QueryString["va1"]);
                    mensual = Processes.Cuotas.GestorCuotas.MetodoBuscarCoutaMes(carnet);
                    anual = Processes.Cuotas.GestorCuotas.MetodoBuscarCuotaAnual(carnet);

                    asdf = DataBase.Miembro.BDMiembro.BuscarMiembro(carnet);

                    Label15.Text = " " + asdf.nombre + " " + asdf.apePaterno + " " + asdf.apeMaterno;
                    if (mensual != null)
                    {
                        anioDeLaBase = mensual.indice / 100;
                        Int64 cod = anioDeLaBase * 100;
                        mesDeLaBase = mensual.indice - cod;
                        Label13.Text = " " + anioDeLaBase;
                        Label17.Text = " " + getNombreMes(mesDeLaBase);
                        DateTime fecha = DateTime.Now;
                        int indMes = fecha.Month;

                        int i = 0;
                        for (int j = i; j < mesDeLaBase; j++)
                        {
                            PintarVerde(j + 1);  //LimeGreen
                            i = j;
                        }
                        //i += 1;


                        i += 2;
                        ///////////////////
                        if (mesDeLaBase < indMes)
                        {
                            if (anioDeLaBase <= DateTime.Now.Year)
                            {
                                for (int j = i; j < indMes; j++)
                                {
                                    PintarRojo(j);
                                    i = j;
                                }
                            }
                        }
                        else
                        {
                            //for (int j = i; j < mesDeLaBase; j++)
                            //{
                            //    PintarVerde(j + 1);  //LimeGreen
                            //    i = j;
                            //}
                            i -= 1;
                        }


                        i += 1;
                        if (anioDeLaBase == DateTime.Now.Year)
                        {
                            for (int j = i; j <= 12; j++)
                            {
                                PintarAzulBajo(j);
                            }
                        }
                        else
                        {
                            for (int j = i; j <= 12; j++)
                            {
                                PintarRojo(j);
                            }
                        }
                        ///////////////////////pintar el mes
                        if (anioDeLaBase == DateTime.Now.Year && mesDeLaBase >= indMes)
                        {
                            PintarVerdePagadoMes(indMes);
                        }
                        else
                        {
                            if (mesDeLaBase != indMes && anioDeLaBase == DateTime.Now.Year)
                            {
                                PintarAzul(indMes);
                            }
                            else
                            {
                                if (anioDeLaBase == DateTime.Now.Year)
                                {
                                    PintarRojo(indMes);
                                }

                            }
                        }

                    }
                    else
                    {
                        for (int i = 0; i <= 12; i++)
                        {
                            PintarAzulBajo(i);
                        }
                        Label13.Text = "Ningun Pago Registrado";
                        Label17.Text = "Ningun Pago Registrado";
                    }
                    if (anual != null) { 
                        Label14.Text = "Gestion: " + anual.indice +" Cancelado"; 

                    }
                    else { 
                        Label14.Text = "Gestion: Ningun Pago Registrado"; }    
                }
                catch (Exception)
                {
                    Label16.Text = "Numero de carnet invalido";
                    MultiView1.ActiveViewIndex = 1;
                }
                
            }
            else
            {
                Label16.Text="No especifico carnet";
                MultiView1.ActiveViewIndex = 1;
            }
            
        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["BuscarMaster"] != null)
            {
                res = (string)Session["BuscarMaster"];
                this.MasterPageFile = res;
            }
        }
        private string getNombreMes(Int64 donde)
        {

            switch (donde)
            {
                case 1:
                    return "Enero ";

                case 2:
                    return "Febrero ";
                case 3:
                    return "Marzo ";
                case 4:
                    return "Abril ";
                case 5:
                    return "Mayo ";
                case 6:
                    return "Junio ";
                case 7:
                    return "Julio ";
                case 8:
                    return "Agosto ";
                case 9:
                    return "Septiembre ";
                case 10:
                    return "Octubre ";
                case 11:
                    return "Noviembre ";
                case 12:
                    return "Diciembre ";

            }
            return "";
        }
        private void PintarVerde(int indice)
        {
            switch (indice)
            {
                case 1:
                    Label1.BackColor = Color.GreenYellow;
                    break;
                case 2:
                    Label2.BackColor = Color.GreenYellow;
                    break;
                case 3:
                    Label3.BackColor = Color.GreenYellow;
                    break;
                case 4:
                    Label4.BackColor = Color.GreenYellow;
                    break;
                case 5:
                    Label5.BackColor = Color.GreenYellow;
                    break;
                case 6:
                    Label6.BackColor = Color.GreenYellow;
                    break;
                case 7:
                    Label7.BackColor = Color.GreenYellow;
                    break;
                case 8:
                    Label8.BackColor = Color.GreenYellow;
                    break;
                case 9:
                    Label9.BackColor = Color.GreenYellow;
                    break;
                case 10:
                    Label10.BackColor = Color.GreenYellow;
                    break;
                case 11:
                    Label11.BackColor = Color.GreenYellow;
                    break;
                case 12:
                    Label12.BackColor = Color.GreenYellow;
                    break;
            }
        }
        private void PintarAzulBajo(int indice)
        {
            switch (indice)
            {
                case 1:
                    Label1.BackColor = Color.PowderBlue;
                    break;
                case 2:
                    Label2.BackColor = Color.PowderBlue;
                    break;
                case 3:
                    Label3.BackColor = Color.PowderBlue;
                    break;
                case 4:
                    Label4.BackColor = Color.PowderBlue;
                    break;
                case 5:
                    Label5.BackColor = Color.PowderBlue;
                    break;
                case 6:
                    Label6.BackColor = Color.PowderBlue;
                    break;
                case 7:
                    Label7.BackColor = Color.PowderBlue;
                    break;
                case 8:
                    Label8.BackColor = Color.PowderBlue;
                    break;
                case 9:
                    Label9.BackColor = Color.PowderBlue;
                    break;
                case 10:
                    Label10.BackColor = Color.PowderBlue;
                    break;
                case 11:
                    Label11.BackColor = Color.PowderBlue;
                    break;
                case 12:
                    Label12.BackColor = Color.PowderBlue;
                    break;
            }
        }
        private void PintarRojo(int indice)
        {
            switch (indice)
            {
                case 1:
                    Label1.BackColor = Color.Red;
                    Label1.ForeColor = Color.White;
                    break;
                case 2:
                    Label2.BackColor = Color.Red;
                    Label2.ForeColor = Color.White;
                    break;
                case 3:
                    Label3.BackColor = Color.Red;
                    Label3.ForeColor = Color.White;
                    break;
                case 4:
                    Label4.BackColor = Color.Red;
                    Label4.ForeColor = Color.White;
                    break;
                case 5:
                    Label5.BackColor = Color.Red;
                    Label5.ForeColor = Color.White;
                    break;
                case 6:
                    Label6.BackColor = Color.Red;
                    Label6.ForeColor = Color.White;
                    break;
                case 7:
                    Label7.BackColor = Color.Red;
                    Label7.ForeColor = Color.White;
                    break;
                case 8:
                    Label8.BackColor = Color.Red;
                    Label8.ForeColor = Color.White;
                    break;
                case 9:
                    Label9.BackColor = Color.Red;
                    Label9.ForeColor = Color.White;
                    break;
                case 10:
                    Label10.BackColor = Color.Red;
                    Label10.ForeColor = Color.White;
                    break;
                case 11:
                    Label11.BackColor = Color.Red;
                    Label11.ForeColor = Color.White;
                    break;
                case 12:
                    Label12.BackColor = Color.Red;
                    Label12.ForeColor = Color.White;
                    break;
            }
        }
        private void PintarVerdePagadoMes(int indice)
        {
            switch (indice)
            {
                case 1:
                    Label1.BackColor = Color.LimeGreen;
                    Label1.ForeColor = Color.White;
                    break;
                case 2:
                    Label2.BackColor = Color.LimeGreen;
                    Label2.ForeColor = Color.White;
                    break;
                case 3:
                    Label3.BackColor = Color.LimeGreen;
                    Label3.ForeColor = Color.White;
                    break;
                case 4:
                    Label4.BackColor = Color.LimeGreen;
                    Label4.ForeColor = Color.White;
                    break;
                case 5:
                    Label5.BackColor = Color.LimeGreen;
                    Label5.ForeColor = Color.White;
                    break;
                case 6:
                    Label6.BackColor = Color.LimeGreen;
                    Label6.ForeColor = Color.White;
                    break;
                case 7:
                    Label7.BackColor = Color.LimeGreen;
                    Label7.ForeColor = Color.White;
                    break;
                case 8:
                    Label8.BackColor = Color.LimeGreen;
                    Label8.ForeColor = Color.White;
                    break;
                case 9:
                    Label9.BackColor = Color.LimeGreen;
                    Label9.ForeColor = Color.White;
                    break;
                case 10:
                    Label10.BackColor = Color.LimeGreen;
                    Label10.ForeColor = Color.White;
                    break;
                case 11:
                    Label11.BackColor = Color.LimeGreen;
                    Label11.ForeColor = Color.White;
                    break;
                case 12:
                    Label12.BackColor = Color.LimeGreen;
                    Label12.ForeColor = Color.White;
                    break;
            }
        }
        private void PintarAzul(int indice)
        {
            switch (indice)
            {
                case 1:
                    Label1.BackColor = Color.MediumBlue;
                    Label1.ForeColor = Color.White;
                    break;
                case 2:
                    Label2.BackColor = Color.MediumBlue;
                    Label2.ForeColor = Color.White;
                    break;
                case 3:
                    Label3.BackColor = Color.MediumBlue;
                    Label3.ForeColor = Color.White;
                    break;
                case 4:
                    Label4.BackColor = Color.MediumBlue;
                    Label4.ForeColor = Color.White;
                    break;
                case 5:
                    Label5.BackColor = Color.Red;
                    Label5.ForeColor = Color.White;
                    break;
                case 6:
                    Label6.BackColor = Color.MediumBlue;
                    Label6.ForeColor = Color.White;
                    break;
                case 7:
                    Label7.BackColor = Color.MediumBlue;
                    Label7.ForeColor = Color.White;
                    break;
                case 8:
                    Label8.BackColor = Color.MediumBlue;
                    Label8.ForeColor = Color.White;
                    break;
                case 9:
                    Label9.BackColor = Color.MediumBlue;
                    Label9.ForeColor = Color.White;
                    break;
                case 10:
                    Label10.BackColor = Color.MediumBlue;
                    Label10.ForeColor = Color.White;
                    break;
                case 11:
                    Label11.BackColor = Color.MediumBlue;
                    Label11.ForeColor = Color.White;
                    break;
                case 12:
                    Label12.BackColor = Color.MediumBlue;
                    Label12.ForeColor = Color.White;
                    break;
            }
        }
    }
}